package chapter1;

import java.util.concurrent.TimeUnit;

public class TryConcurrency {
    public static void main(String[] args) {
//        browserNews();
//        enjoyMusic();

        new Thread(){
            @Override
            public void run(){
                enjoyMusic();
            }
        }.start();
        browserNews();
    }

    private static void enjoyMusic() {
        for (;;){
            System.out.println("the nice music");
            sleep(1);
        }
    }

    private static void sleep(int i) {
        try {
            TimeUnit.SECONDS.sleep(i);//抛出中断异常InterruptedException
        } catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    private static void browserNews() {
        for (;;){
            System.out.println("the good news");
            sleep(1);
        }
    }
    Thread thread = new Thread();
}
